<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <span th:include="~{include::cssStyle}"></span>
    <script>
        $(function (){
            //修改
            $(".btn-primary").click(function (){
                location="/student/find/"+$(this).val();
            })
            $("#all").click(function (){
                $("[name='chk']").prop("checked",$(this).prop("checked"));
            })
            //删除
            $(".btn-warning").click(function (){
                let $name = $("[name='chk']:checked");
                 if($name.length == 0){
                     alert("请选择！");
                 }else{
                     let ids="?";
                     if(confirm("确认要删除吗？")){
                         $name.each(function (){
                            ids += 'ids='+ $(this).val()+'&';
                         })
                         alert(ids);
                         $.get(
                             '/student/delete/'+ids,
                             function (obj){
                                 if(obj){
                                     alert("ok");
                                     location.reload();
                                 }else{
                                     alert("删除失败！");
                                 }
                             }
                         )

                     }
                 }

            })
        })
    </script>
</head>
<body>
        <div class="container">
           <table class="table table-bordered table-hover">
             <tr>
               <th>编号</th>
               <th>姓名</th>
               <th>性别</th>
               <th>生日</th>
               <th>头像</th>
                 <th>
                     <input type="checkbox" id="all">全选
                     <button class="btn btn-warning">删除</button>
                 </th>
               <th>
                 <button class="btn btn-success" onclick="location='add'">新增</button>
               </th>
             </tr>
             <tr th:each="stu:${pager.records}" th:object="${stu}">

                <td th:text="*{id}"></td>
                <td th:text="*{name}"></td>
                <td th:text="*{sex} ==0 ? '男': '女'"></td>
                <td th:text="*{#dates.format(birthday,'yyyy-MM-dd')}"></td>
                <td>
                    <img width="50px" height="50px" th:src="@{'/static/upload/'+ *{pic}}">
                </td>
                 <td><input type="checkbox" name="chk" th:value="*{id}"></td>
                 <td>
                     <button class="btn btn-primary" th:value="*{id}">更新</button>
                 </td>
             </tr>
               <tr>
                   <td colspan="10" align="center">
                       共<span th:text="${pager.total}"></span>条记录，
                       共<span th:text="${pager.pages}"></span>页,
                       当前是第<span th:text="${pager.current}"></span>页。
                       <a th:href="@{/student/list(offset=1)}">首页</a>
                       <a th:if="${pager.hasPrevious()}" th:href="@{/student/list(offset=${pager.current}-1)}">上页</a>
                       <a th:if="${pager.hasNext()}" th:href="@{/student/list(offset=${pager.current}+1)}">下页</a>
                       <a th:href="@{/student/list(offset=${pager.pages})}">末页</a>
                   </td>
               </tr>
           </table>
        </div>
</body>
</html>
